﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ABELGX
{
    /// <summary>
    /// UserControlTextItem.xaml 的交互逻辑
    /// </summary>
    public partial class UserControlTextItem : UserControl
    {
        public UserControlTextItem()
        {
            InitializeComponent();
        }
        public void SetSensor(Sensor sensor)
        {
            if (sensor == null)
            {
                return;
            }
            LabelTitle.Content = $"{sensor.Set.Name}：";
            LabelValue.DataContext = sensor;
        }
        public void SetRegisterBool(string name,RegisterBool registerBool)
        {
            if(registerBool == null)
            {
                return;
            }
            LabelTitle.Content = $"{(string.IsNullOrWhiteSpace(name) ? registerBool.Set.Name : name)}：";
            Binding textBinding = new Binding();
            textBinding.Source = registerBool;
            textBinding.Path = new PropertyPath("Text");
            textBinding.Mode = BindingMode.OneWay;
            LabelValue.SetBinding(Label.ContentProperty, textBinding);

            Binding colorBinding = new Binding();
            colorBinding.Source = registerBool;
            colorBinding.Path = new PropertyPath("Color");
            colorBinding.Mode = BindingMode.OneWay;
            LabelValue.SetBinding(Label.ForegroundProperty, colorBinding);

            LabelValue.DataContext = registerBool;
        }
    }
}
